Supported MAC algorithms
This section describes the MAC algorithms that are available with the Provider through the javax.crypto.Mac interface. A sample code fragment for generating a MAC code is also provided.
DES MAC
This algorithm is compatible with FIPS PUB 113 as well as ANSI X9.9.
The MAC can be initialized using any valid DES key (see DES). The result MAC value will be a 4-byte array.
DESede MAC
This algorithm is compatible with FIPS PUB 113.
The MAC can be initialized using any valid DESede key (see DESede). The result MAC value will be a 4-byte array.
DESedeX919 MAC
This MAC implements the triple DES MAC algorithm as defined in X9.19 (or ISO 9807).
The MAC can be initialized using any valid DESede key (see DESede). The result MAC value will be a 4-byte array.
IDEA MAC
This algorithm is compatible with FIPS PUB 113.
The MAC can be initialized using any valid IDEA key (see IDEA). The result MAC value will be a 4-byte array.
CAST128 MAC
This algorithm is compatible with FIPS PUB 113.
The MAC can be initialized using any valid CAST128 key (see CAST128). The result MAC value will be a 4-byte array.
RC2
This algorithm is compatible with FIPS PUB 113.
The MAC can be initialized using any valid RC2 key (see RC2). The result MAC value will be a 4-byte array.
HMAC/MD2
This HMAC implements the HMAC algorithm as defined in RFC 2104 using the message digest function MD2. The result MAC value will be a 16-byte array.
The MAC can be initialized using a SecretKeySpec with the algorithm name “HMAC/MD2”. It is also possible to initialize this MAC using any of the secret keys generated by one of the KeyGenerator classes or KeyFactory classes, as detailed in Supported ciphers.
HMAC/MD5
This HMAC implements the HMAC algorithm as defined in RFC 2104 using the message digest function MD5. The result MAC value will be a 16-byte array.
The MAC can be initialized using a SecretKeySpec with the algorithm name “HMAC/MD5”. It is also possible to initialize this MAC using any of the secret keys generated by one of the KeyGenerator classes or KeyFactory classes, as detailed in Supported ciphers.
HMAC/SHA1
This HMAC implements the HMAC algorithm as defined in RFC 2104 using the message digest function SHA1. The result MAC value will be a 20-byte array.
The MAC can be initialized using a SecretKeySpec with the algorithm name “HMAC/SHA1”. It is also possible to initialize this MAC using any of the secret keys generated by one of the KeyGenerator classes or KeyFactory classes, as detailed in Supported ciphers.
HMAC/SHA224
This HMAC implements the HMAC algorithm as defined in RFC 2104 using the message digest function SHA224. The result MAC value will be a 28-byte array.
The MAC can be initialized using a SecretKeySpec with the algorithm name “HMAC/SHA224”. It is also possible to initialize this MAC using any of the secret keys generated by one of the KeyGenerator classes or KeyFactory classes, as detailed in Supported ciphers.
HMAC/SHA256
This HMAC implements the HMAC algorithm as defined in RFC 2104 using the message digest function SHA256. The result MAC value will be a 32-byte array.
The MAC can be initialized using a SecretKeySpec with the algorithm name “HMAC/SHA256”. It is also possible to initialize this MAC using any of the secret keys generated by one of the KeyGenerator classes or KeyFactory classes, as detailed in Supported ciphers.
HMAC/SHA384
This HMAC implements the HMAC algorithm as defined in RFC 2104 using the message digest function SHA384. The result MAC value will be a 48-byte array.
The MAC can be initialized using a SecretKeySpec with the algorithm name “HMAC/SHA384”. It is also possible to initialize this MAC using any of the secret keys generated by one of the KeyGenerator classes or KeyFactory classes, as detailed in Supported ciphers.
HMAC/SHA512
This HMAC implements the HMAC algorithm as defined in RFC 2104 using the message digest function SHA512. The result MAC value will be a 64-byte array.
The MAC can be initialized using a SecretKeySpec with the algorithm name “HMAC/SHA512”. It is also possible to initialize this MAC using any of the secret keys generated by one of the KeyGenerator classes or KeyFactory classes, as detailed in Supported ciphers.
Sample MAC Code
This sample code fragment will generate a MAC code (based on a randomly generated DES key) for the bytes in the string "hello world".
KeyGenerator keyGen = KeyGenerator.getInstance("DES", "SAFENET");
Key desKey = keyGen.generateKey();
Mac desMac = Mac.getInstance("DES", "SAFENET");
desMac.init(desKey);
byte[] mac = desMac.doFinal("hello world".getBytes());